﻿@model IList<SpotsHub.RouteService.Data.Driver>
@using Telerik.Web.Mvc;
@using Telerik.Web.Mvc.UI
@using Nop.Web.Framework.UI

@{
    Html.AppendScriptParts("/subsites/logistics/Presentation/Web/Scripts/map-bing-1.0.js");
    Html.AppendScriptParts("https://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0");
}

<div>
    @{
        string val = "";
    }

    @if (Model.Count == 1)
    {
        @Html.Action("DisplayMap", "Route", new { driverId = Model.First().Id } );
        <script type="text/javascript">
            $(document).ready(function () {
                getMap();
            });

        </script>
    }
    else if (Model.Count == 0)
    {
        @Html.Action("Index");
    }
    else
    {

        var drivers = new List<SelectListItem>();

        for (int i = 0; i < Model.Count; i++)
        {
            drivers.Add(new SelectListItem() { Text = Model[i].DisplayName, Value = Model[i].Id.ToString() });
        }
        
        @Html.DropDownListFor(m => val, drivers);
        
        <input type="button" id="show-map" class="t-button" value="Show Map" />

        <div id="mapph" />
        <script type="text/javascript">
            $(document).ready(function(){
                $("#show-map").click(function(){
                    $.get("@Url.Action("DisplayMap")?driverId=" + $('#@Html.FieldIdFor(m => val)').val(), 
                        function(data,status){
                            $("#mapph").html(data);
                            getMap();
                        });
                });
            });
        </script>
    }

</div>


